/*
 * @features: 对Component组件的扩展
 * @description: 说明
 * @Date: 2021-09-13 23:09:34
 * @Author: judu233(769471424@qq.com)
 * @LastEditTime: 2021-10-10 19:41:11
 * @LastEditors: judu233
 */

import c3d from "../../cc";
import ExtendsLoad from "../CCExtends";
import { ComponentEventExtends } from "./Util/ComEvent";

declare module "cc" {
    export interface Component {
        /**获取组件的名字 */
        getComName(): string;
        /**获取组件的transform */
        trans(): UITransform;
        /**获取组件的sprite组件 */
        sp(): Sprite;
        /**获取组件的Label组件 */
        lb(): Label;
    }
}

class ComponentExtends {
    static getComName() { return this.name.match(/(?<=\<).+(?=\>)/g)[0]; }
    static trans() { return (this as unknown as c3d.Component).getComponent(c3d.UITransform); }
    static sp() { return (this as unknown as c3d.Component).getComponent(c3d.Sprite); }
    static lb() { return (this as unknown as c3d.Component).getComponent(c3d.Label); }
}
ExtendsLoad.load(c3d.Component.prototype, ComponentExtends, true);
ExtendsLoad.load(c3d.Component.prototype, ComponentEventExtends, true);

